
<script>
  $(document).ready(function() {
    $("#submission_common_name" ).autocomplete({
        source: birdArray
    });
	
	$(".subHead").on("click",function(event) {
		var titleName = $(this).attr("id");
		var divName = titleName.replace("Title","");
		
		if($("#" + divName).is(":visible")) {
			$("#" + divName).slideUp();
		}
		else {
			$("#" + divName).slideDown();
		}
	});
	
	$(".expand").attr("title","Click to show or hide");
		
});
   var birdArray = <%= Bird.all.map(&:common_name).sort.to_json.html_safe %>;
   
   
   function validateSubmission()
   {
		var isValid = true;
		
		//format time correctly
		var sightTime = $("#sightTime").val();
		var sightDate = $("#sight_date_time").val();
		
		$("#sight_date_time").val(sightDate + " " + sightTime);
		//3:00 
		//YYYY-MM-DD hh:mm:ss
		
		//alert(sightTime);
		
		
		
		return isValid;
   }
   

</script>
 <% if @submission.bird_id %>
  <% @common_name = Bird.find(@submission.bird_id).common_name if (@submission.bird_id !=31) %>
  <% @common_name = @submission.common_name if (@submission.bird_id ==31) %>
  <% end %>
  <%= form_for(@submission) do |f| %>
  <% if @submission.errors.any? %>
	<div style="" id="error_explanation">
	<span style="font-size:large;color:red;">The following errors have prevented this submission from being saved...</span>
	  <ul style="color:red;">
	  <% @submission.errors.full_messages.each do |msg| %>
		<li><%= msg %></li>
	  <% end %>
	  </ul>
	</div>
  <% end %>
  <span id="birdInfoTitle" class="subHead expand">Bird Information</span><span class="help">(Click title to show or hide this group)</span>
  <div class="subGroup" id="birdInfo">
	<span style="font-size:medium;color:red;">(* All fields in this group must be entered, if you don't know the information enter &quot;Unknown&quot; or &quot;None&quot;)</span>
	<br><br>
  	<div class="subLabel">
		<span>Common Bird Name</span>
		<%= f.text_field :common_name, :value=>@common_name%><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>Number of Birds</span>
		<%= f.number_field :num_of_birds %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>Age of Bird(s)</span>
		<%= f.text_field :age %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>Sex of Bird(s)</span>
		<%= f.text_field :sex %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:30px;">General Plumage (Breeding, nonbreeding, etc)</span>
		<%= f.text_area :plumage, :rows => "5", :cols => "65" %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Detailed Description of Bird</span>
		<%= f.text_area :detailed_description, :rows => "5", :cols => "45" %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Detailed Behavior of Bird (Flight pattern, feeding, etc.)</span>
		<%= f.text_area :detailed_behavior, :rows => "5", :cols => "45" %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:30px;">Distinguishing Characteristics From Other Species</span>
		<%= f.text_area :distinguished_char, :rows => "5", :cols => "45" %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Habitat Description</span>
		<%= f.text_area :habitat, :rows => "5", :cols => "45" %><span class="required">*</span>
	</div>
  </div>
  
  <br/>
  <br/>
  <span id="subInfoTitle" class="subHead expand">Submission Information</span><span class="help">(Click title to show or hide this group)</span>
  <div class="subGroup" id="subInfo">
  <span style="font-size:medium;color:red;">(All fields in this group must be entered, if you don't know the information enter &quot;Unknown&quot; or &quot;None&quot;)</span>
  <br>
  <br>
	<div class="subLabel">
		<span>Reporting Observers</span>
		<%= f.text_field :coobservers %><span class="required">*</span>

	</div>
	<br>
	<div class="subLabel">
		<span>Location</span>
		<%= f.text_field :location %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>GPS Coordinates</span>
		<%= f.text_field :gps %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>Sighting Date</span>
		<%= f.datetime_select :sight_date_time, :class => "timeSelect", :ampm =>true%> <span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>Length of Observation</span>
		<%= f.text_field :length_of_obs %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>Distance from Bird</span>
		<%= f.text_field :distance_from %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Optical Equipment</span>
		<%= f.text_area :optical_equipment, :rows => "5", :cols => "45" %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">References Used</span>
		<%= f.text_area :references, :rows => "5", :cols => "45" %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span>Submission made</span>
		<%= f.radio_button :sub_recall,"0",:style =>"width:20px;",:checked => true %>During Sighting
		<br>
		<%= f.radio_button :sub_recall,"1",:style =>"margin-left:204px;width:20px;" %>After Sighting
	</div>
	<br>
	<div class="subLabel">
		<span>Do you consider this sighting unusual?</span>
		<%= f.check_box :unusual, :style => "width:20px;" %>Yes
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Previous Experience With This Bird Species</span>
		<%= f.text_area :prev_bird_exp, :rows => "5", :cols => "45" %><span class="required">*</span>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Notes</span>
		<%= f.text_area :notes, :rows => "5", :cols => "45" %>
	</div>
	<br>
	<div class="subLabel">
		<span>Multimedia</span>
		<br />
		<% @multimedia.each_with_index do |multimedium, index| %>
			<%= f.fields_for :multimedia, multimedium do |multimedia_fields| %>
				<% if multimedia_fields.object.image? && !multimedia_fields.object.new_record?%>			
					<%= image_tag(multimedia_fields.object.image_url(:thumb)) %>
					<%= multimedia_fields.check_box :_destroy %> Delete
				<% end %>

				<% if multimedia_fields.object.video? && !multimedia_fields.object.new_record?%>			
					<%= link_to image_tag("video.png", :size => "100x100"), multimedium.video_url.to_s %>
					<%= multimedia_fields.check_box :_destroy %> Delete
				<% end %>
				
				<% if multimedia_fields.object.audio? && !multimedia_fields.object.new_record?%>			
					<%= link_to image_tag("audio.png", :size => "100x100"), multimedium.audio_url.to_s %>
					<%= multimedia_fields.check_box :_destroy %> Delete
				<% end %>
			<% end %>
		<% end %>
		
		<%= f.fields_for  :multimedia, @image do |image_fields| %>
			<% if image_fields.object.new_record? %>
				<br />
				Image: <%= image_fields.file_field :image, :onchange => "validateImage(this);", :data=> {:max_file_size => 5.megabytes} %>
				(Up to 5mb)
				<br />
			<% end %>
		<% end %>
		
		<%= f.fields_for  :multimedia, @video do |video_fields| %>
			<% if video_fields.object.new_record? %>
				<br />
				Video: <%= video_fields.file_field :video, :onchange => "validateVideo(this);", :data=> {:max_file_size => 15.megabytes} %>
				(Up to 15mb)
				<br />
			<% end %>
		<% end %>
		
		<%= f.fields_for  :multimedia, @audio do |audio_fields| %>
			<% if audio_fields.object.new_record? %>
				<br />
				Audio: <%= audio_fields.file_field :audio, :onchange => "validateAudio(this);", :data=> {:max_file_size => 5.megabytes} %>
				(Up to 5mb)
				<br />
			<% end %>
		<% end %>

		<br />
	</div>
  </div>
  
  <br/>
  <br/>

  <% if isadmin? && params[:action] != "new"%> 
  <span id="adminInfoTitle" class="subHead expand">Administrator Information</span><span class="help">(Click title to show or hide this group)</span>
  <div class="subGroup" id="adminInfo">
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Working Notes</span>
		<%= f.text_area :working_notes, :rows => "5", :cols => "45" %>
	</div>
	<br>
	<div class="subLabel">
		<span style="position:relative; bottom:29px;">Administrator Notes</span>
		<%= f.text_area :admin_notes, :rows => "5", :cols => "45" %>
	</div>
	<br>
	<div class="subLabel">
		<span>Category of Acceptance</span>
		<%= f.text_field :s_degree %>
	</div>
	<br>
	<div class="subLabel">
		<span>Region</span>
		<%= f.text_field :region %>
	</div>
	<br>
	<div class="subLabel">
		<span>Voting Date</span>
		<%= f.datetime_select :date_votable, :class => "timeSelect", :ampm =>true%> 
	</div>
	<br>
	<div class="subLabel">
		<span>Submission Status</span>
		<%= f.select :status, options_for_select(submission_statuses, @submission.status)%>
	</div>
	<br>
	<div class="subLabel">
		<span>Round</span>
		<%= f.select :rounds, options_for_select([[1,1],[2,2],[3,3]], @submission.rounds) %>
	</div>
  </div>
  <% end %>
  <br/>
  <br/>
  	<!-- Display Save as Draft if this is a new submission or this submission is incomplete and belongs to the logged in user -->
	<% if @submission.status == "incomplete" %>
		<%= f.submit "Save as Draft", :class => "btn-custom", :style => "display:inline-block;"%>
	<% end %>
	<%= f.submit "Submit",:class => "btn-custom", :onclick => "return validateSubmission();" %>
<% end %>
